package com.example.demo.controller;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/login")
    public Boolean login(HttpServletRequest request,String username, String password) {
        Boolean result = false;
        if(StringUtils.hasLength(username) && StringUtils.hasLength(password)) {
            if(username.equals("admin") && password.equals("admin")) {
                HttpSession session = request.getSession(true);
                session.setAttribute("userinfo","userinfo");
                result = true;
            }
        }
        return result;
    }
    @RequestMapping("/reg")
    public Boolean reg() {
        return true;
    }

    @RequestMapping("/index")
    public String index() {
        return "hello,index";
    }
}
